package com.isoft.airportsystem.service.impl;


import com.isoft.airportsystem.entity.AIRL.ARPT;
import com.isoft.airportsystem.entity.AIRL.DFLT_AIRL;
import com.isoft.airportsystem.entity.META;
import com.isoft.airportsystem.mapper.AIRLMapper;
import com.isoft.airportsystem.mapper.MetaMapper;
import com.isoft.airportsystem.service.AIRLService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class AIRLServiceImpl implements AIRLService {
    @Resource
    private AIRLMapper airlMapper;

    @Resource
    private MetaMapper metaMapper;
    @Override
    public Integer add(DFLT_AIRL airl, META meta) {
        String apnoid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
        String metaid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
        airlMapper.add(airl,apnoid,metaid);
        if(!airl.getArpt().isEmpty()){
            for (ARPT arpt : airl.getArpt()) {
                addARPT(arpt,apnoid);
            }
        }
        metaMapper.add(meta,metaid);
        return null;
    }

    @Override
    public Integer addARPT(ARPT arpt, String apnoid) {
        return airlMapper.addARPT(arpt, apnoid);
    }
}
